0

messingaround.ipynb

No Headings

The table of contents shows headings in notebooks and supported files.

Skip to Main
Jupyter

messingaround

Last Checkpoint: 6 hours ago
  • File
  • Edit
  • View
  • Run
  • Kernel
  • Settings
  • Help
JupyterLab
Python 3 (ipykernel)
Kernel status: Idle Executed 1 cellElapsed time: 6 seconds
    [52]:
    %gui osx
    [53]:
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline

    def create_wavy_pattern(width=800, height=600, num_lines=100, frequency=0.02, amplitude=30):
    # Set up the figure
    plt.figure(figsize=(20, 15), facecolor='black')
    ax = plt.gca()
    ax.set_facecolor('black')
    # Create base y-coordinates for lines (evenly spaced)
    y_base = np.linspace(0, height, num_lines)
    # Create x-coordinates
    x = np.linspace(0, width, 1000)
    # Create each wavy line
    for y_start in y_base:
    # Create wave deformation
    # Use multiple sine waves for more organic look
    deformation = (
    amplitude * np.sin(frequency * x + y_start/50) +
    amplitude/2 * np.sin(frequency*2 * x - y_start/30) +
    amplitude/4 * np.sin(frequency/2 * x + y_start/20)
    )
    # Add the deformation to the base y-position
    y = y_start + deformation
    # Plot the line
    plt.plot(x, y, color='white', linewidth=1, alpha=1)
    # Set the display parameters
    plt.axis('off')
    plt.xlim(0, width)
    plt.ylim(0, height)
    # Remove padding
    plt.tight_layout(pad=0)
    # Display the plot
    plt.show()

    # Generate the pattern
    create_wavy_pattern(
    width=800,
    height=600,
    num_lines=120, # Adjust for line density
    frequency=0.015, # Adjust for wave frequency
    amplitude=40 # Adjust for wave height
    )

    # Optionally save the image
    # plt.savefig('wavy_pattern.png', bbox_inches='tight', pad_inches=0, dpi=300, facecolor='black')
    [26]:
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation
    %matplotlib inline
    from IPython.display import HTML

    class WaveAnimator:
    def __init__(self, width=800, height=600, num_lines=100, frequency=0.02, amplitude=30):
    self.width = width
    self.height = height
    self.num_lines = num_lines
    self.frequency = frequency
    self.amplitude = amplitude
    # Set up the figure
    self.fig = plt.figure(figsize=(4, 3), facecolor='black')
    self.ax = plt.gca()
    self.ax.set_facecolor('black')
    # Create base coordinates
    self.y_base = np.linspace(0, height, num_lines)
    self.x = np.linspace(0, width, 1000)
    # Initialize empty line objects
    self.lines = []
    for _ in range(num_lines):
    line, = self.ax.plot([], [], color='white', linewidth=1, alpha=1)
    self.lines.append(line)
    # Set the display parameters
    plt.axis('off')
    plt.xlim(0, width)
    plt.ylim(0, height)
    plt.tight_layout(pad=0)
    def init(self):
    for line in self.lines:
    line.set_data([], [])
    return self.lines
    def animate(self, frame):
    # Convert frame to radians for smoother cyclic effects
    t = frame * 2 * np.pi / 100
    # Update each line
    for i, line in enumerate(self.lines):
    y_start = self.y_base[i]
    # Dynamic amplitude modulation
    amp_mod = 1 + 0.3 * np.sin(t/2 + y_start/100)
    # Dynamic frequency modulation
    freq_mod = 1 + 0.2 * np.cos(t/3 + y_start/200)
    # Create wave deformation with multiple dynamic components
    deformation = (
    # Primary wave with moving phase and amplitude modulation
    self.amplitude * amp_mod * np.sin(
    self.frequency * freq_mod * self.x + y_start/50 + t
    ) +
    # Secondary wave with different phase and direction
    self.amplitude/2 * np.sin(
    self.frequency*2 * self.x - y_start/30 + t*1.5 +
    0.1 * np.sin(t/2) # Phase distortion
    ) +
    # Tertiary wave for complexity
    self.amplitude/4 * np.sin(
    self.frequency/2 * self.x + y_start/20 - t*0.7
    ) +
    # Breathing effect
    self.amplitude/3 * np.sin(t/2) * np.sin(self.x/200 + y_start/100) +
    # Standing wave pattern
    self.amplitude/5 * np.sin(t) * np.sin(self.x/100)
    )
    # Add vertical drift
    vertical_drift = 10 * np.sin(t/3 + y_start/100)
    # Set the new line data
    line.set_data(self.x, y_start + deformation + vertical_drift)
    return self.lines

    def create_animated_pattern():
    animator = WaveAnimator(
    width=800,
    height=600,
    num_lines=120,
    frequency=0.015,
    amplitude=40
    )
    # Create animation
    anim = FuncAnimation(
    animator.fig,
    animator.animate,
    init_func=animator.init,
    frames=200,
    interval=40,
    blit=True
    [26]:
    Your browser does not support the video tag.
    [19]:
    Your browser does not support the video tag.
    [20]:
    Your browser does not support the video tag.
    [22]:
    Selection deleted
    from IPython.display import HTML, Image, clear_output
    import base64
    from datetime import datetime
    import ipywidgets as widgets
    from matplotlib.animation import PillowWriter

    # Create control widgets
    num_lines = widgets.IntSlider(
    value=400,
    min=100,
    max=800,
    description='Lines:',
    style={'description_width': 'initial'}
    )

    frequency = widgets.FloatSlider(
    value=0.015,
    min=0.005,
    max=0.03,
    step=0.001,
    description='Frequency:',
    style={'description_width': 'initial'}
    )

    amplitude = widgets.IntSlider(
    value=40,
    min=10,
    max=80,
    description='Amplitude:',
    style={'description_width': 'initial'}
    )

    fps_slider = widgets.IntSlider(
    create_animation(None)
    400
    0.01
    40
    15
    Generating animation...
    
    Quick preview version:
    
    [29]:
    Your browser does not support the video tag.
    160
    0.30
    1.00
    0.10
    146
    0.35
    1.50
    0.50
    333
    4
    0.50
    Pinch Point 1
    0.90
    0.10
    0.10
    Pinch Point 2
    0.90
    0.10
    0.10
    Pinch Point 3
    0.40
    0.20
    0.10
    Pinch Point 4
    0.10
    0.40
    0.10
    Importing py5 on macOS but the necessary Jupyter macOS event loop has not been activated. I'll activate it for you, but next time, execute `%gui osx` before importing this library.
    
    100
    2
    0.50
    Flow Pattern 1
    0.20
    0.50
    0.20
    1.00
    Flow Pattern 2
    0.40
    0.50
    0.20
    1.00
    Flow Pattern 3
    0.60
    0.50
    0.20
    1.00
    Flow Pattern 4
    0.80
    0.50
    0.20
    1.00
    ---------------------------------------------------------------------------
    Exception                                 Traceback (most recent call last)
    File PApplet.java:1761, in processing.core.PApplet.createGraphics()
    
    Exception: Java Exception
    
    The above exception was the direct cause of the following exception:
    
    java.lang.NullPointerException            Traceback (most recent call last)
    /var/folders/s4/y20zrdnj7yl52r9qt_41h5380000gn/T/ipykernel_45251/3212741496.py in ?(button)
        189 def update_art(button):
    --> 190     with output:
        191         clear_output(wait=True)
        192         display(create_separate_flows())
    
    /var/folders/s4/y20zrdnj7yl52r9qt_41h5380000gn/T/ipykernel_45251/3212741496.py in ?(width, height)
        118 def create_separate_flows(width=1200, height=600):
    --> 119     art = py5.create_graphics(width, height)
        120 
        121     def generate_single_flow(center_x, center_y, flow_width, spread, line_count):
        122         # Generate one complete flow pattern
    
    /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/__init__.py in ?(*args)
       4459     with `create_graphics()` can have transparency. This makes it possible to draw
       4460     into a graphics and maintain the alpha channel. By using `save()` to write a
       4461     `PNG` or `TGA` file, the transparency of the graphics object will be honored.
       4462     """
    -> 4463     return _py5sketch.create_graphics(*args)
    
    /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/graphics.py in ?(self_, *args)
         50     @functools.wraps(f)
         51     def decorated(self_, *args):
    ---> 52         ret = f(self_, *args)
         53         if ret is not None:
         54             return Py5Graphics(ret)
    
    /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/sketch.py in ?(self, *args)
       9120         with `create_graphics()` can have transparency. This makes it possible to draw
       9121         into a graphics and maintain the alpha channel. By using `save()` to write a
       9122         `PNG` or `TGA` file, the transparency of the graphics object will be honored.
       9123         """
    -> 9124         return self._instance.createGraphics(*args)
    
    java.lang.NullPointerException: java.lang.NullPointerException: Cannot invoke "processing.core.PGraphics.isGL()" because "this.g" is null
    2024-10-25 13:19:39.177 Python[45251:1680429] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
    
    36
    4
    0.30
    0.90
    125.00
    Flow 1
    0.20
    0.30
    Flow 2
    0.40
    0.70
    Flow 3
    0.40
    0.30
    Flow 4
    0.80
    0.30
    4
    50
    0.10
    0.50
    100
    200
    [11]:
    Your browser does not support the video tag.
    5
    40
    0.10
    0.80
    200
    400
    1/6

    -

    Variables

    Callstack

      Breakpoints

      Source

      9
      1

      Kernel Sources

      Common Tools
      No metadata.
      Advanced Tools
      No metadata.
      ⌥ [
      ⌥ ]
      ⌥ ↘
      • Console
      • Change Kernel…
      • Clear Console Cells
      • Close and Shut Down…
      • Insert Line Break
      • Interrupt Kernel
      • New Console
      • Restart Kernel…
      • Run Cell (forced)
      • Run Cell (unforced)
      • Show All Kernel Activity
      • Debugger
      • Breakpoints on exception
      • Evaluate Code
        Evaluate Code
      • Next
        Next
        F10
      • Pause
        Pause
        F9
      • Step In
        Step In
        F11
      • Step Out
        Step Out
        ⇧ F11
      • Terminate
        Terminate
        ⇧ F9
      • Display Languages
      • English
        English
      • File Operations
      • Autosave Documents
      • Download
        Download the file to your computer
      • Reload Notebook from Disk
        Reload contents from disk
      • Revert Notebook to Checkpoint…
        Revert contents to previous checkpoint
      • Save Notebook
        Save and create checkpoint
        ⌘ S
      • Save Notebook As…
        Save with new path
        ⇧ ⌘ S
      • Trust HTML File
        Whether the HTML file is trusted. Trusting the file allows scripts to run in it, which may result in security risks. Only enable for files you trust.
      • Help
      • About Jupyter Notebook
      • Jupyter Reference
      • JupyterLab FAQ
      • JupyterLab Reference
      • Launch Jupyter Notebook File Browser
      • Markdown Reference
      • Show Keyboard Shortcuts…
        Show relevant keyboard shortcuts for the current active widget
        ⇧ ⌘ H
      • Image Viewer
      • Flip image horizontally
        H
      • Flip image vertically
        V
      • Invert Colors
        I
      • Reset Image
        0
      • Rotate Clockwise
        ]
      • Rotate Counterclockwise
        [
      • Zoom In
        =
      • Zoom Out
        -
      • Kernel Operations
      • Shut Down All Kernels…
      • Main Area
      • Close All Other Tabs
      • Close Tab
        ⌥ W
      • Close Tabs to Right
      • End Search
        ⎋
      • Find Next
        ⌘ G
      • Find Previous
        ⇧ ⌘ G
      • Find…
        ⌘ F
      • Log Out
        Log out of Jupyter Notebook
      • Search in Selection
        ⌥ L
      • Shut Down
        Shut down Jupyter Notebook
      • Mode
      • Toggle Zen Mode
      • Notebook Cell Operations
      • Change to Code Cell Type
        Y
      • Change to Heading 1
        1
      • Change to Heading 2
        2
      • Change to Heading 3
        3
      • Change to Heading 4
        4
      • Change to Heading 5
        5
      • Change to Heading 6
        6
      • Change to Markdown Cell Type
        M
      • Change to Raw Cell Type
        R
      • Clear Cell Output
        Clear outputs for the selected cells
      • Collapse All Code
      • Collapse All Outputs
      • Collapse Selected Code
      • Collapse Selected Outputs
      • Copy Cell
        Copy this cell
        C
      • Cut Cell
        Cut this cell
        X
      • Delete Cell
        Delete this cell
        D, D
      • Disable Scrolling for Outputs
      • Enable Scrolling for Outputs
      • Expand All Code
      • Expand All Outputs
      • Expand Selected Code
      • Expand Selected Outputs
      • Extend Selection Above
        ⇧ K
      • Extend Selection Below
        ⇧ J
      • Extend Selection to Bottom
        ⇧ ↘
      • Extend Selection to Top
        ⇧ ↖
      • Insert Cell Above
        Insert a cell above
        A
      • Insert Cell Below
        Insert a cell below
        B
      • Insert Heading Above Current Heading
        ⇧ A
      • Insert Heading Below Current Heading
        ⇧ B
      • Merge Cell Above
        ⌃ ⌫
      • Merge Cell Below
        ⌃ ⇧ M
      • Merge Selected Cells
        ⇧ M
      • Move Cell Down
        Move this cell down
        ⌃ ⇧ ↓
      • Move Cell Up
        Move this cell up
        ⌃ ⇧ ↑
      • Paste Cell Above
        Paste this cell from the clipboard
      • Paste Cell and Replace
      • Paste Cell Below
        Paste this cell from the clipboard
        V
      • Redo Cell Operation
        ⇧ Z
      • Render Side-by-Side
        ⇧ R
      • Run Selected Cell
        Run this cell and advance
        ⇧ ⏎
      • Run Selected Cell and Do not Advance
        ⌘ ⏎
      • Run Selected Cell and Insert Below
        ⌥ ⏎
      • Run Selected Text or Current Line in Console
      • Select Cell Above
        K
      • Select Cell Below
        J
      • Select Heading Above or Collapse Heading
        ←
      • Select Heading Below or Expand Heading
        →
      • Set side-by-side ratio
      • Split Cell
        ⌃ ⇧ -
      • Undo Cell Operation
        Z
      • Notebook Operations
      • Access Next Kernel History Entry
        ⌥ ↓
      • Access Previous Kernel History Entry
        ⌥ ↑
      • Change Kernel…
      • Clear Outputs of All Cells
        Clear all outputs of all cells
      • Close and Shut Down Notebook…
      • Collapse All Headings
        ⌃ ⇧ ←
      • Deselect All Cells
      • Edit Notebook Metadata
      • Enter Command Mode
        ⌃ M
      • Enter Edit Mode
        ⏎
      • Expand All Headings
        ⌃ ⇧ →
      • Interrupt Kernel
        Interrupt the kernel
      • New Console for Notebook
      • New Notebook
        Create a new notebook
      • Reconnect to Kernel
      • Render All Markdown Cells
      • Restart Kernel and Clear Outputs of All Cells…
        Restart the kernel and clear all outputs of all cells
      • Restart Kernel and Debug…
        Restart Kernel and Debug…
      • Restart Kernel and Run All Cells…
        Restart the kernel and run all cells
      • Restart Kernel and Run up to Selected Cell…
      • Restart Kernel…
        Restart the kernel
      • Run All Above Selected Cell
      • Run All Cells
        Run all cells
      • Run Selected Cell and All Below
      • Save and Export Notebook: Asciidoc
      • Save and Export Notebook: Executable Script
      • Save and Export Notebook: HTML
      • Save and Export Notebook: LaTeX
      • Save and Export Notebook: Markdown
      • Save and Export Notebook: PDF
      • Save and Export Notebook: Qtpdf
      • Save and Export Notebook: Qtpng
      • Save and Export Notebook: ReStructured Text
      • Save and Export Notebook: Reveal.js Slides
      • Save and Export Notebook: Webpdf
      • Select All Cells
        ⌘ A
      • Show Line Numbers
      • Toggle Collapse Notebook Heading
      • Trust Notebook
      • Other
      • Open in JupyterLab
        JupyterLab
      • Plugin Manager
      • Advanced Plugin Manager
      • Terminal
      • Decrease Terminal Font Size
      • Increase Terminal Font Size
      • New Terminal
        Start a new terminal session
      • Refresh Terminal
        Refresh the current terminal session
      • Use Terminal Theme: Dark
        Set the terminal theme
      • Use Terminal Theme: Inherit
        Set the terminal theme
      • Use Terminal Theme: Light
        Set the terminal theme
      • Text Editor
      • Decrease Font Size
      • Increase Font Size
      • New Markdown File
        Create a new markdown file
      • New Python File
        Create a new Python file
      • New Text File
        Create a new text file
      • Spaces: 1
      • Spaces: 2
      • Spaces: 4
      • Spaces: 4
      • Spaces: 8
      • Theme
      • Decrease Code Font Size
      • Decrease Content Font Size
      • Decrease UI Font Size
      • Increase Code Font Size
      • Increase Content Font Size
      • Increase UI Font Size
      • Set Preferred Dark Theme: JupyterLab Dark
      • Set Preferred Dark Theme: JupyterLab Dark High Contrast
      • Set Preferred Dark Theme: JupyterLab Light
      • Set Preferred Dark Theme: JupyterLab Night
      • Set Preferred Light Theme: JupyterLab Dark
      • Set Preferred Light Theme: JupyterLab Dark High Contrast
      • Set Preferred Light Theme: JupyterLab Light
      • Set Preferred Light Theme: JupyterLab Night
      • Synchronize Styling Theme with System Settings
      • Theme Scrollbars
      • Use Theme: JupyterLab Dark
      • Use Theme: JupyterLab Dark High Contrast
      • Use Theme: JupyterLab Light
      • Use Theme: JupyterLab Night
      • View
      • File Browser
      • Open JupyterLab
      • Show Debugger
        Show Show Debugger in the right sidebar
      • Show Header
      • Show Notebook Tools
        Show Show Notebook Tools in the right sidebar
      • Show Table of Contents
        Show Show Table of Contents in the left sidebar